<template>
  <view>
    <!-- 选择地址的按钮
     -->
    <view class="address-chose-box" v-if="JSON.stringify(address)=='{}'">
      <button type="primary" size="mini" @click="btnChoseAddress">请选择收货地址+</button>
    </view>
    <!-- 
    还是，原来的那种写法,
    如果满足条件了，就展示，反之不满足条件就不展示
     -->
    <view class="address-info-box" v-else>
      <view class="row1">
        <view class="row1-left">
          <view class="username">收货人:{{address.userName}}</view>
        </view>
        <view class="row1-right"  @click="btnChoseAddress">
          <view class="phone">电话:{{address.telNumber}}</view>
          <uni-icons type="arrowright" size="16"></uni-icons>
        </view> 
      </view>
      <view class="row2">
        <view class="row2-left">收货地址:</view>
        <view class="row2-right">
         {{addStr}}
        </view>
      </view>
      
    </view>
    <!-- 底部的边框线 -->
    <image src="../../static/分割线.jpg" mode="widthFix" class="address-border"></image>
  </view>
</template>

<script>
  export default {
    name:"my-address",
    data() {
      return {
        // 表示收货地址
        address:uni.$user._state.data.address,
        // 表示地址详细信息
        addStr:''
      };
    },
    methods:{
      async btnChoseAddress(){
        /*
        实现收货地址功能
        */
       const res= await uni.chooseAddress().catch(err=>err)
       if(res.errMsg=="chooseAddress:ok"){
        uni.$user._mutations.updateAddress[0](res)
        this.address=res
        this.addStr=uni.$user.getters.addStr
       }
      }
    }
  }
</script>

<style lang="scss">
.address-border{
  display: block;
  width: 100%;
}
.address-chose-box{
  height: 90px;
  display: flex;
  justify-content: center;
  align-items: center;
}
.address-info-box{
  font-size: 12px;
  height: 90px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 5px;
  .row1{
    display: flex;
    justify-content: space-between;
    .row1-right{
      display: flex;
      justify-content: space-between;
    }
  }
  .row2{
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
    .row2-left{
      white-space: nowrap;
    }
  }
}
</style>